<template>
    <van-address-edit 
        show-set-default
        :area-list="areaList"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        :address-info="address"
        @save="save"
    />
</template>

<script setup>
    //引入地区数据
    import { areaList } from '@vant/area-data'

    const {proxy} = getCurrentInstance()

    let business = proxy.$business.value

    let address = ref({
        name: business.nickname,
        tel: business.mobile,
        areaCode: business.district || business.city || business.province,
    })

    const save = async (values) => {
        console.log(values)

        var params = {
            busid: business.id,
            consignee: values.name,
            address: values.addressDetail,
            mobile: values.tel,
            status: values.isDefault ? 1 : 0,
            code: values.areaCode
        }

        var result = await proxy.$POST({url: 'address/add', params})

        if(result.code == 0)
        {
            proxy.$fail(result.msg)
            return false
        }

        proxy.$success({
            message:result.msg,
            duration: 1000,
            onClose: () => proxy.$router.go(-1)
        })
    }
</script>